package com.ruoyi.procurement.design.handler;

import com.ruoyi.procurement.design.ProcurementStateEnum;
import com.ruoyi.procurement.design.ProcurementStateHandlerAbs;
import com.ruoyi.procurement.domain.ProcurementModel;
import com.ruoyi.procurement.domain.ProcurementOrder;
import com.ruoyi.procurement.mapper.ProcurementOrderMapper;
import com.ruoyi.warehousing.domain.Warehousing;
import com.ruoyi.warehousing.mapper.WarehousingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 待审核状态流转
 */
@Component
public class ProcurementPendingHandler extends ProcurementStateHandlerAbs {

    @Override
    public String get() {
        return ProcurementStateEnum.PENDING.getCode();
    }

    @Autowired
    private ProcurementOrderMapper procurementOrderMapper;

    @Autowired
    private WarehousingMapper warehousingMapper;

    @Override
    public Integer transferTo(ProcurementOrder procurementOrder, String state) {
        procurementOrder.setProcurementStatus(state);
        procurementOrder.setAuditTime(null);
        return procurementOrderMapper.updateProcurementOrder(procurementOrder);
    }

    @Override
    public void operationWareHousing(ProcurementOrder procurementOrder) {
        // 获取订单中的产品
        List<ProcurementModel> models =
                procurementOrderMapper.selectProcurementModelById(procurementOrder.getProcurementWarehousingId());
        // 库存对象列表
        models.stream().map(
                model -> Warehousing
                        .builder()
                        .deptId(model.getDeptId())
                        .productId(model.getProductId())
                        .productType(model.getProductType())
                        .batch(model.getBatch())
                        .medicalNumber(model.getMedicalNumber())
                        .medicalEndTime(model.getMedicalEndTime())
                        .effectiveDate(model.getEffectiveDate())
                        .productionDate(model.getProductionDate())
                        .build()
        ).collect(Collectors.toList()).forEach(item -> {
            // 判断是否存在当前
            Integer count = warehousingMapper.isExist(item);

        });




        // warehousingMapper.selectWarehousing();
    }
}
